package com.magneticattraction.service;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.CompoundButton;
import android.widget.Switch;

public class MainActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {

    private static final String TAG = "MainActivity";
    private Switch aSwitch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        aSwitch = findViewById(R.id.send);
        aSwitch.setOnCheckedChangeListener(this);


    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked){
            Log.d(TAG, "onCheckedChanged: 发送广播");
            System.out.println("onCheckedChanged: 发送广播");
            //ReceiveAndSendService receiveAndSendService = new ReceiveAndSendService();
            Intent intent = new Intent();
            intent.putExtra("sensor", "sensor_data");
            //intent.setComponent(new ComponentName(getPackageName(), "com.magneticattraction.testnfc.SensorReceiver11.class"));//显示指定组件名称
            intent.setPackage("com.magneticattraction.testnfc");
            intent.setAction("android.intent.action.STATIC_BROADCAST");
            sendBroadcast(intent);
            Log.d(TAG, "onCheckedChanged: 发送广播成功");
            System.out.println("onCheckedChanged: 发送广播成功");
           // receiveAndSendService.sendBroadcast(intent);
        }
    }
}